<?php
$result=[];//存放删除记录返回的结果
try {
    if (!$_GET['xh'])throw new Exception('必须提供要删除记录的学号信息~');
    session_start();
    $hasRight=$_SESSION['user']['xh']===$_GET['xh'] || $_SESSION['user']['isAdmin'];//判断用户是否有修改的权限
    if(!$hasRight)throw new Exception('对不起，你没有删除他人记录的权限~');
    $db = new PDO("mysql:host=localhost;dbname=db5", 'root', '12qwas');
    $ps=$db->prepare(query: 'delete from students where xh=? and isAdmin=0');
    $ps->execute(array($_GET['xh']));
    if ($ps->rowCount()===0)throw new Exception('删除失败~');//删除的记录不存在；删除的记录是管理员
    if ($_SESSION['user']['xh']===$_GET['xh']){
        unset($_SESSION['user']);//注销用户
        $result['logout']=true;
    }
    $result['ok']=true;
}catch(Exception $e){
    $result['ok']=false;
    $result['$msg']=$e->getMessage();
}
echo json_encode($result, JSON_UNESCAPED_UNICODE);
